package com.nwpu.coursesupport.view.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.nwpu.coursesupport.controller.AbstractController;
import com.nwpu.coursesupport.entity.bean.JSONResult;
import com.nwpu.coursesupport.enumeration.TaskType;
import com.nwpu.coursesupport.service.imple.LessonTaskViewService;
import com.nwpu.coursesupport.view.criteria.LessonTaskViewSearchCriteria;

@Controller
@RequestMapping("/lessonTaskView")
public class LessonTaskViewController extends AbstractController{

	@Autowired
	private LessonTaskViewService lessonTaskViewService;
	
	@RequestMapping("/ajaxTlview")
	@ResponseBody
	public JSONResult ajaxTeacherView(@RequestParam("data")String data){
		JSONResult rst=invokeService("lessonTaskView", "getTeacherView", data);
		return rst;
	}
	@RequestMapping("/tlview")
	public String teacherView(@RequestParam("lessonId")int lessonId,String type,HttpServletRequest request){
		JSONResult rst=new JSONResult();
		rst.fail();
		LessonTaskViewSearchCriteria sc=new LessonTaskViewSearchCriteria();
		sc.setLessonId(lessonId);
		if(type==null){
			
		}else if(type.equals(TaskType.HOMEWORK.name())){
			sc.setType(TaskType.HOMEWORK);
		}else if(type.equals(TaskType.LABTEST.name())){
			sc.setType(TaskType.LABTEST);
		}else if(type.equals(TaskType.TESTINLESSON.name())){
			sc.setType(TaskType.TESTINLESSON);
		}else if(type.equals(TaskType.ASKINLESSON.name())){
			sc.setType(TaskType.ASKINLESSON);
		}
		rst=lessonTaskViewService.getTeacherView(sc);
		request.setAttribute("data", this.parseData(rst));
		return "/teapage/classroomTask";
	}
	
	@RequestMapping("/ajaxStuView")
	@ResponseBody
	public JSONResult ajaxStudentView(@RequestParam("data")String data){
		JSONResult rst=invokeService("lessonTaskView", "getStudentView", data);
		return rst;
	}
	@RequestMapping("/stuView")
	public String StudentView(@RequestParam("lessonId")int lessonId,String type,HttpServletRequest request){
		JSONResult rst=new JSONResult();
		rst.fail();
		LessonTaskViewSearchCriteria sc=new LessonTaskViewSearchCriteria();
		sc.setLessonId(lessonId);
		if(type==null){
			
		}else if(type.equals(TaskType.HOMEWORK.name())){
			sc.setType(TaskType.HOMEWORK);
		}else if(type.equals(TaskType.LABTEST.name())){
			sc.setType(TaskType.LABTEST);
		}else if(type.equals(TaskType.TESTINLESSON.name())){
			sc.setType(TaskType.TESTINLESSON);
		}else if(type.equals(TaskType.ASKINLESSON.name())){
			sc.setType(TaskType.ASKINLESSON);
		}
		rst=lessonTaskViewService.getStudentView(sc);
		request.setAttribute("data", this.parseData(rst));
		return "/stupage/lessonTask";
	}
}
